package com.elvin.smartgethttp;

import org.apache.http.Header;

import android.os.Bundle;
import android.util.Log;

import com.tandong.sa.activity.SmartActivity;
import com.tandong.sa.loopj.AsyncHttpClient;
import com.tandong.sa.loopj.AsyncHttpResponseHandler;
import com.tandong.sa.loopj.RequestParams;

public class HttpActivity extends SmartActivity {
	
	private AsyncHttpClient client = new AsyncHttpClient();
	private final String Server = "http://10.3.131.196";
	private final String getURL = Server+"/www/androidServer/index.php/Home/SmartHttp/phpGet";
	private final String postURL = Server+"/www/androidServer/index.php/Home/SmartHttp/phpPost";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		client.get(getURL, new AsyncHttpResponseHandler() {
        	
			@Override
			public void onSuccess(int statusCode, Header[] headers, byte[] response) {
				// TODO Auto-generated method stub
				//String aa =  Integer.toString(statusCode);
				showToast(new String(response));
				
				Log.i("MainActivity", new String(response));
				
			}
			
			@Override
			public void onFailure(int statusCode, Header[] headers, byte[] errorResponse,
					Throwable e) {
				// TODO Auto-generated method stub
				showToast("get onFailure");
			}


        	
        });
        
        RequestParams params = new RequestParams();
		params.put("name", "smartandroid");
		params.put("password", "123456");

		client.post(postURL, params, new AsyncHttpResponseHandler() {
			@Override
			public void onSuccess(int statusCode, Header[] headers, byte[] response) {
				// TODO Auto-generated method stub
				showToast("post onSuccess");
			}

			@Override
			public void onFailure(int statusCode, Header[] headers, byte[] errorResponse,
					Throwable e) {
				// TODO Auto-generated method stub
				showToast("post onFailure");
			}
		});
	}
}
